package com.shushan.web;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;

/**
 * @ClassName: GoodsDetailWebActivity
 * @Desciption: 商品详情H5
 * @author: yichaohua
 * @date: 2018-05-12
 */
public class GoodsDetailWebActivity extends BaseWebActivity{

    private static final String TAG = "GoodsDetailWebActivity";

    private static final String SUCCESS_URL = "shushanbao://127.0.0.1/toyexchanged";//兑换成功拦截url
    private static final String FAILURE_URL = "shushanbao://127.0.0.1/earnxuebei";//兑换失败点击“赚学贝”url
    private static final String BACK_URL = "shushanbao://127.0.0.1/notvipback";//非vip点击退出
    private static final String BUY_URL = "shushanbao://127.0.0.1/notvipbuy";//非vip点击购买

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mWebView.setWebViewClient(mWebViewClient);
    }

    WebViewClient mWebViewClient = new WebViewClient(){

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            if(url.contains(SUCCESS_URL)){
                onBackAction(200);
            }else if(url.contains(FAILURE_URL)){
                onBackAction(300);
            }else if(url.contains(BACK_URL)) {
                onBackAction();
            }else if(url.contains(BUY_URL)) {
                onBackAction(500);
            }else {
                view.loadUrl(url);
            }
            return true;
        }

    };
}
